﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace Medicalsystem.MCP.FormDesigner.Property
{
    /// <summary>
    /// 下拉列表式编辑
    /// </summary>
    public class ContentEditorDropDown : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                return UITypeEditorEditStyle.DropDown;
            }

            return base.GetEditStyle(context);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            IWindowsFormsEditorService editorService = null;

            if (context != null && context.Instance != null && provider != null)
            {
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (editorService != null)
                {
                    System.Windows.Forms.TextBox TB = new System.Windows.Forms.TextBox();
                    TB.Multiline = true;
                    TB.Size = new System.Drawing.Size(300, 200);
                    TB.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    TB.AcceptsReturn = true;

                    TB.Text = value.ToString();

                    service.DropDownControl(TB);
                    value = TB.Text;
                }
            }

            return value;
        }
    }
}